package gugu.services.impl;

import javax.annotation.Resource;

import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.stereotype.Component;
import gugu.domain.User;
import gugu.services.UserService;
import static gugu.domain.User.UserType.ACTIVE;
import static gugu.domain.User.UserType.INACTIVE;
import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Query.query;
@Component("userService")
public class UserServiceImpl implements UserService {
	
	@Resource
	private MongoOperations mongoOpts;
	
	@Override
	public User getUser(String userGuid) {
		return mongoOpts.findById(userGuid,User.class);
	}

	@Override
	public User getUserByAccount(String userAccount) {
		return  mongoOpts.findOne(query(where("contactEmail").is(userAccount)),User.class);
	}

	@Override
	public void createUser(User user) {
		user.setType(ACTIVE);
		mongoOpts.insert(user);
	}

	@Override
	public void disableUser(User user) {
		user.setType(INACTIVE);
		mongoOpts.save(user);
	}

}
